//
//  HXAskOpinionTableViewController.m
//  KD
//
//  Created by ifly on 16/8/10.
//  Copyright © 2016年 Whx. All rights reserved.
//

#import "HXAskOpinionTableViewController.h"
#import "HXOpinionDetailTableViewController.h"
#import "HXFeedBackGetKindDataModel.h"
#import "HXEditOpinionViewController.h"

@interface HXAskOpinionTableViewController ()

@property (nonatomic,strong) NSMutableArray <HXFeedBackGetKindDataResultModel *>*numArray;

@end

@implementation HXAskOpinionTableViewController

static NSString * cellID = @"HXAskOpinionTableViewController";

/**加载数据*/
-(void)getDatas{

    self.numArray = [NSMutableArray array];
    
    [NetworkAPI getFeedBackGetKindDataWithKindType:1
                                        withDataID:@""
                                           Success:^(HXFeedBackGetKindDataModel *result) {
                                               
                                               if ([result.code integerValue] == 200) {
                                                   [self.numArray addObjectsFromArray:result.result];
                                                   [self.tableView reloadData];
                                               }
                                               
                                           } failure:^(NSError *err) {
                                               [SVProgressHUD showErrorWithStatus:@"网络错误!"];
                                           }];
}



- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"意见反馈";
    [self getDatas];
//    self.view.backgroundColor = [UIColor olive];
    
//    _numArray = [[NSMutableArray alloc] initWithObjects:@"皮卡丘",@"小火龙",@"妙蛙种子",@"呆河马",@"迷你龙",@"火爆猴",@"大岩蛇",@"皮皮",@"椰蛋树", nil];
    
    //[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _numArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.textLabel.text = _numArray[indexPath.row].DataText;
    return cell;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    
    return @"请选择发生的问题";
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 40.f;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [self getDetailDatasWithModel:self.numArray[indexPath.row]];
}

-(void)getDetailDatasWithModel:(HXFeedBackGetKindDataResultModel *)model{
    
    NSMutableArray * dataArray = [NSMutableArray array];
    [NetworkAPI getFeedBackGetKindDataWithKindType:2
                                        withDataID:model.DataID
                                           Success:^(HXFeedBackGetKindDataModel *result) {
                                               
                                               if ([result.code integerValue] == 200) {
                                                   
                                                   [dataArray addObjectsFromArray:result.result];
                                                   HXOpinionDetailTableViewController * vc = [[HXOpinionDetailTableViewController alloc] initWithNsmutableArray:dataArray withDataText:model.DataText];
                                                   [self.navigationController pushViewController:vc animated:YES];
                                                   
                                               }else {
                                                   
                                                   HXEditOpinionViewController * editVc = [[HXEditOpinionViewController alloc] initWithQueText:model.DataText withSceneText:@""];
                                                   [self.navigationController pushViewController:editVc animated:YES];
                                               }
                                               
                                           } failure:^(NSError *err) {
                                               [SVProgressHUD showErrorWithStatus:@"网络错误!"];
                                           }];
}




@end





